import React from 'react';
import { Form, Input, Button, InputNumber } from 'antd';
import { WhseSelect } from '@/components/FormItemSelect';
import PartSelect from '@/components/PartSelect';

const FormItem = Form.Item;

const formLayout = {
  labelCol: { span: 6 },
  wrapperCol: { span: 14 },
};

export default class InvCheckModal extends React.Component<any, any> {
  constructor(props: any) {
    super(props);
    this.state = {
      loading: true,
    };
  }

  formRef: any = React.createRef();
  handleSubmit = (values: any) => {
    const { onSubmit } = this.props;
    if (typeof onSubmit === 'function') {
      onSubmit(values);
    }
  };
  setCurrent = (part?: any) => {
    var PartBOM: any = {};
    PartBOM.partNum = part.partNum;
    PartBOM.partDescription = part.partDescription;
    PartBOM.ium = part.ium;
    this.formRef.current.setFieldsValue(PartBOM);
  };
  componentDidMount() {
    const { formVals } = this.props;
    if (formVals) {
      this.formRef.current.setFieldsValue(formVals);
      this.setState({ loading: false });
    }
  }
  formRender = () => {
    return (
      <Form {...formLayout} ref={this.formRef} onFinish={this.handleSubmit}>
        <Form.Item label="物料">
          <Input.Group compact>
            <PartSelect
              name="partNum"
              noStyle
              width={200}
              required={true}
              placeholder="物料编码"
              setCurrent={this.setCurrent}
            />
          </Input.Group>
        </Form.Item>
        <FormItem
          name="partDescription"
          label="描述"
          rules={[{ required: true, message: '请输入描述' }]}
        >
          <Input.TextArea disabled />
        </FormItem>
        <FormItem
          name="ium"
          label="单位"
          rules={[{ required: true, message: '请输入单位' }]}
        >
          <Input disabled style={{width:60}} />
        </FormItem>
        <WhseSelect
          label="仓库"
          showSearch={false}
          required={true}
          name={'warehouseCode'}
          placeholder="仓库"
        />
        <FormItem
          name="binNum"
          label="库位"
          rules={[{ required: true, message: '请输入库位' }]}
        >
          <Input placeholder="请输入库位" />
        </FormItem>
        <FormItem name="lotNum" label="批次">
          <Input placeholder="请输入批次" />
        </FormItem>
        <FormItem name="onhandQty" label="现存量">
          <InputNumber placeholder="请输入现存量" min={0} />
        </FormItem>
        <FormItem wrapperCol={{ offset: 6 }}>
          <Button type="primary" htmlType="submit">
            确认
          </Button>
        </FormItem>
      </Form>
    );
  };
  render() {
    const FormRender = this.formRender;

    return <FormRender />;
  }
}
